package xyz.ddlnt.serviceusr.controller;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import xyz.ddlnt.commonutil.result.Result;
import xyz.ddlnt.model.dto.NoteAddDTO;
import xyz.ddlnt.model.dto.NoteDTO;
import xyz.ddlnt.model.dto.NoteDirDTO;
import xyz.ddlnt.model.vo.NoteContentVO;
import xyz.ddlnt.model.vo.NoteVO;
import xyz.ddlnt.serviceusr.service.NoteService;

import java.util.List;

/**
 * @author ZZULI_SE 210910
 * @data 2025/5/6 21:51
 */
@Slf4j
@RequestMapping("/note")
@RestController
public class NoteController {

    @Resource
    private NoteService noteService;

    /**
     * 新增笔记
     * @param noteAddDTO
     * @return
     */
    @PostMapping("/addNote")
    public Result<NoteVO> addNote(@RequestBody NoteAddDTO noteAddDTO) {
        return Result.success(noteService.addNote(noteAddDTO));
    }

    /**
     * 删除笔记
     * @param id
     * @return
     */
    @DeleteMapping("/deleteNote")
    public Result<Boolean> deleteNote(@RequestParam Long id) {
        return Result.success(noteService.removeById(id));
    }

    /**
     * 修改笔记标题
     * @param noteDTO
     * @return
     */
    @PutMapping("/updateNoteTitle")
    public Result<Boolean> updateNoteTitle(@RequestBody NoteDTO noteDTO) {
        return Result.success(noteService.updateNoteTitle(noteDTO));
    }

    /**
     * 更新笔记
     * @param noteDTO
     * @return
     */
    @PutMapping("/updateNote")
    public Result<Boolean> updateNote(@RequestBody NoteDTO noteDTO) {
        return Result.success(noteService.updateNote(noteDTO));
    }

    /**
     * 更新笔记前节点子集
     * @param noteDirDTO
     * @return
     */
    @PutMapping("/updateNoteChildNodes")
    public Result<Boolean> updateNoteChildNodes(@RequestBody NoteDirDTO noteDirDTO) {
        return Result.success(noteService.updateNoteChildNodes(noteDirDTO));
    }

    /**
     * 获取笔记目录·
     * @param noteDirDTO
     * @return
     */
    @PostMapping("/getNoteDir")
    public Result<List<NoteVO>> getNoteDir(@RequestBody NoteDirDTO noteDirDTO) {
        return Result.success(noteService.getNote(noteDirDTO));
    }

    /**
     * 获取笔记内容
     * @param id
     * @return
     */
    @GetMapping("/getNoteContent")
    public Result<NoteContentVO> getNoteContent(@RequestParam Long id) {
        return Result.success(noteService.getNoteContent(id));
    }

}
